
import React, { createContext, useState, useContext } from 'react';
const AuthContext = createContext();


export const AuthProvider = ({ children }) => {
    const year = new Date().getFullYear();
    const [token, setToken] = useState(localStorage.getItem('token'));
    const login = (newToken) => {
        localStorage.setItem('token', newToken);
        setToken(newToken);
    };
    const logout = () => {
        localStorage.removeItem('token');
        setToken(null);
    };
    return (
        <AuthContext.Provider value={{ token, login, logout }}>
            {children}
            <div style={{
                backgroundColor: '#000',
                height: '100px',
                textAlign: 'center',
                lineHeight: '100px',
                color: '#fff',
            }}>
                @ {year} <a href="https://beian.miit.gov.cn/" target='_blank' style={{ color: '#fff' }} rel="noreferrer">
                    蜀ICP备2024091226号
                </a>

            </div>
        </AuthContext.Provider>
    );
};
export const useAuth = () => useContext(AuthContext);